// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** 注册用户 POST /api/register */
export async function register(body: API.RegisterParams, options?: { [key: string]: any }) {
  const formData = `&username=${body.username}&password=${body.password}`;
  return request<API.RegisterResult>('/api/register', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: formData,
    ...(options || {}),
  });
}

/** 获取验证码 GET /api/captcha */
export async function getCaptcha(params: API.CaptchaParams, options?: { [key: string]: any }) {
  return request<API.CaptchaResult>('/api/captcha?uuid=' + params.uuid, {
    method: 'GET',
    ...(options || {}),
  });
}

/** 登录接口 POST /api/login */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  const formData = `&username=${body.username}&password=${body.password}&captcha=${body.captcha}&uuid=${body.uuid}`;

  return request<API.LoginResult>('/api/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: formData,
    ...(options || {}),
  });
}

/** 获取首页数据 GET /api/home */
export async function getHomeData(options?: { [key: string]: any }) {
  return request<API.HomeDataResult>('/api/home', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取稽核工单数据 GET /api/orders */
export async function getAuidtOrders(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  const res = await request<API.AuditOrdersResult>('/api/order', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
  return {
    ...res,
    data: res.orderlist,
    total: res.total || 10,
    success: res.no === '0',
  };
}

/** 获取积分数据 GET /api/points */
export async function getPoints(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  const res = await request<API.PointListResult>('/api/points', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
  return {
    ...res,
    data: res.PointsInfo,
    total: res.total || 10,
    success: res.no === '0',
  };
}

/** 获取当前的用户 GET /api/currentUser */
export async function currentUser(options?: { [key: string]: any }) {
  return request<{
    data: API.CurrentUser;
  }>('/api/currentUser', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 授权稽核工单(单个) GET /api/order/auth */
export async function auditOrderAuth(
  params: {
    // query
    /** 当前流水号 */
    serialnum?: string;
  },
  options?: { [key: string]: any },
) {
  // TODO: 为什么是 get
  return request<API.AuditAuthResult>('/api/order/auth', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// TODO: 后面的接口都是没实现的.

/** 退出登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/api/login/outLogin', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 此处后端没有提供注释 GET /api/notices */
export async function getNotices(options?: { [key: string]: any }) {
  return request<API.NoticeIconList>('/api/notices', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取规则列表 GET /api/rule */
export async function rule(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<API.RuleList>('/api/rule', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 更新规则 PUT /api/rule */
export async function updateRule(options?: { [key: string]: any }) {
  return request<API.RuleListItem>('/api/rule', {
    method: 'POST',
    data: {
      method: 'update',
      ...(options || {}),
    },
  });
}

/** 新建规则 POST /api/rule */
export async function addRule(options?: { [key: string]: any }) {
  return request<API.RuleListItem>('/api/rule', {
    method: 'POST',
    data: {
      method: 'post',
      ...(options || {}),
    },
  });
}

/** 删除规则 DELETE /api/rule */
export async function removeRule(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/api/rule', {
    method: 'POST',
    data: {
      method: 'delete',
      ...(options || {}),
    },
  });
}
